/********************************************************************************
 * Copyright (c)2016-2020, ShenZhen WanJiaAn Technology CO.,LTD.
 * All Rights Reserved.
 *
 * File Name     : UartMsg.h
 * Author        : joki.zhu
 * Date          : 2019-11-18
 *
 * Record        :
 * 1.Date        : 2019-11-18
 *   Author      : joki.zhu
 *   Modification: Created file
 ********************************************************************************/

#ifndef __MCU_UPDATE_MSG__H__
#define __MCU_UPDATE_MSG__H__

#include "av_type.h"
#include "UartDevConf.h"

#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */


#define UARTMSG_CMD_DATA_MAX_LEN     (512)


//SOC<=== UART ===>MCU
typedef enum {	
    UARTMSG_S2M_UPGRADE_DATA_INDEX_MIN      = 0x00,
    UARTMSG_S2M_UPGRADE_DATA_INDEX_MAX      = 0x7F,
	
	//SOC -> MCU
	UARTMSG_S2M_UPGRADE_START               = 0x80,
    UARTMSG_S2M_UPGRADE_PARAMS              = 0x81,
    UARTMSG_S2M_UPGRADE_END                 = 0x82,

    //MCU -> SOC
	UARTMSG_M2S_UPGRADE_START_ACK           = 0xA0,
	UARTMSG_M2S_UPGRADE_PARAMS_ACK          = 0xA1,
    UARTMSG_M2S_UPGRADE_END_ACK             = 0xA2,

	UARTMSG_LAST,
} UARTMSG_MSGID_E;


#pragma  pack (push,1)                //1字节对齐


typedef struct
{
    UARTMSG_MSGID_E     u32MsgId;                       //事件消息ID号
    AV_U8               data[UARTMSG_CMD_DATA_MAX_LEN];
    AV_U16              dataLen;
} UARTMSG_PARM_S;

#pragma pack(pop)

typedef void (*UartMsgRecvCallback)(UARTMSG_PARM_S *pRcvMsg);

int UartMsgInit(void);
int UartMsgRegisterRecv(UartMsgRecvCallback pRecvCallback);
int UartMsgUnRegisterRecv(UartMsgRecvCallback pRecvCallback);
int UartMsgSendData(UARTMSG_MSGID_E msgId, AV_U8 *pData, AV_U16 dataLen);
int UartMsgSendMsg(UARTMSG_PARM_S *pSendMsg);
int UartMsgSendMsgAndWaitMsg(UARTMSG_PARM_S *pSendMsg, UARTMSG_PARM_S *pWaitMsg, AV_U32 timeoutMs);
int UartMsgDeinit(void);


#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */


#endif /* __MCU_UPDATE_MSG__H__ */

